import 'package:flutter/material.dart';

///
/// 动态修改Appbar导航栏背景透明度
///
class QCommonTansAppBar extends AppBar {
  QCommonTansAppBar({
    Key? key,
    required double opacity,
    required Function() clickBack,
    String? title, // 标题
    double fontSize = 16, // 标题文字大小
    FontWeight fontWeight = FontWeight.normal, // 标题文字粗细
    bool showBack = true, // 是否显示返回按钮
    List<Widget>? actions, // 右侧按钮集合
    Color? backIconColor, // 返回按钮背景颜色
    String? backIconPath, // 返回按钮图片地址
  }) : super(
          key: key,
          backgroundColor: Color.fromRGBO(255, 255, 255, opacity),
          elevation: 0,
          leadingWidth: 25,
          title: Offstage(
            offstage: title != null ? false : true,
            child: Text(
              title ?? "标题",
              style: TextStyle(
                fontSize: fontSize,
                fontWeight: fontWeight,
                color: opacity > 0.4
                    ? Color.fromRGBO(0, 0, 0, opacity)
                    : Colors.white,
              ),
            ),
          ),
          leading: showBack
              ? GestureDetector(
                  onTap: clickBack,
                  child: Container(
                    margin: const EdgeInsets.only(left: 8, top: 4, bottom: 4),
                    width: 16,
                    height: 16,
                    padding: const EdgeInsets.all(2),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(3),
                        color: backIconColor ?? const Color(0x20FFFFFF)),
                    child: backIconPath == null
                        ? Icon(
                            Icons.arrow_back_ios,
                            color: opacity > 0.4
                                ? Color.fromRGBO(0, 0, 0, opacity)
                                : Colors.white,
                          )
                        : Image.asset(
                            backIconPath,
                            width: 12,
                            height: 12,
                            color: opacity > 0.4
                                ? Color.fromRGBO(0, 0, 0, opacity)
                                : Colors.white,
                          ),
                  ),
                )
              : Container(),
          actions: actions ?? [],
        );
}